package com.hetang.controller;

import com.hetang.domain.User;
import com.hetang.domain.UserRequestDTO;
import com.hetang.domain.common.MsgResponse;
import com.hetang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import java.util.Map;

/**
 * @author 詹泽
 * @date 2017/3/3
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @ResponseBody
    public MsgResponse<User> getUser(@PathVariable int id){
        return userService.getUser(id);
    }

    @ResponseBody
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public MsgResponse<Object> deleteUser(@PathVariable String id){
        return userService.deleteUser(id);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.PUT)
    public MsgResponse<Object> addUser(User user){
        return userService.addUser(user);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public MsgResponse<Object> updateUser(User user){
        return userService.updateUser(user);
    }

    @ResponseBody
    @RequestMapping(value = "/status/{id}/{status}",method = RequestMethod.POST)
    public MsgResponse<Object> updateStatus(@PathVariable String id,@PathVariable int status){
        return userService.updateStatus(id,status);
    }

    @ResponseBody
    @RequestMapping(value = "",method = RequestMethod.GET)
    public MsgResponse<List<User>> listUser(UserRequestDTO userRequestDTO){
        return userService.listUser(userRequestDTO);
    };
}
